function Employ_Code() {
	var buffer = new StringBuffer();
	buffer.append('<div id="find" class="finds"><div class="searchinput ui-border-radius"><input id="keyword" class="bordersolid" type="text" value="" onblur="Show_Search()" onkeyup="Employ_Search();"/></div><div id="searchicon" class="searchicon"><img src="img/jing.jpg"/></div><div id="searchicons" class="searchicons"><img src="img/jings.jpg"/></div><div class="screen"><button id="screen" class="ui-border-radius">筛选</button></div></div>');
	buffer.append('<div class="horizen border-bottom"></div>');
	return buffer.toString();
};
function Employ_Data(data) {
	var buffer = new StringBuffer();
	$(data).each(function(i,info){
		buffer.append('<div class="matelist border-bottom" id="'+info.ID+'" roleid="'+info.RoleID+'"><div class="matename"><div class="realname">'+info.RealName+'</div><div class="birthplace greens state">'+info.StateText+'</div></div><div class="mateinfo"><div class="sex">'+info.Sex+'</div><div class="joindate interviewdate">招聘时间：<font>'+info.InterviewDate.ToDate()+'</font></div></div></div>');
	});
	return buffer.toString();
};
function Init_Employ_Code()
{
	get("find").addEventListener("tap",function(){
		$("#searchicon").hide();
	    $("#searchicons").show();
	    $("#keyword").attr("placeholder","姓名、电话");
		if($("keyword").val()!="")
		{
			//WorkMate_Search();
		}
	});
	get("screen").addEventListener("tap",function(){
		OpenScreen(Employ_Search_Code(),function(){
			Init_Employ_Search();
		},Employ_Search);
		stopEvent();
	});
};

function Init_Employ_Search(){
	mui(".option").on("tap",".date",function(){
		obj=this;
			var t=new Date();
			if($(this).val()!="")
			{
				var year_month_day=$(this).val().split("-");
				t.setFullYear(year_month_day[0]);
				t.setMonth(year_month_day[1]-1);
				t.setDate(year_month_day[2]);
			}
			plus.nativeUI.pickDate( function(e){
				var d=e.date;
				$(obj).val((d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate()).ToDate());
			},function(e){
				console.log( "未选择日期："+e.message );
			},{date:t});
	});
};

function Employ_Search_Code()
{
	var buffer = new StringBuffer();
	buffer.append('<div class="searchline" style="margin-top:10px;"><div class="names">招聘状态</div><div class="option"><select id="state_search"><option value="">全部</option><option value="1">初试</option><option value="2">复试</option><option value="3">通过</option><option value="4">淘汰</option></select></div></div>');
	buffer.append('<div class="searchline"><div class="names">招聘时间</div><div class="option"><input id="begindate_search" type="text" class="date" placeholder="开始时间" readonly="readonly"/><input id="enddate_search" type="text" class="date" placeholder="结束时间" readonly="readonly"/></div></div>');
	return buffer.toString();
};
function Employ_Search(){
	pageindex=1;
	$("#divmsg1").attr("pageindex","0");
	Receive_Employ(1);
};
function Receive_Employ(pageindex)
{
	var data = {};
			data.act = "Find_Employ";
			data.userid=userid;
			data.comid=comid;
			data.pageindex=pageindex;
			data.source=source;
			data.pagesize=PAGE_SIZE20;
			data.keyword = $("#keyword").val();
			data.timer = RUndefined($("#begindate_search").val()) + "～" + RUndefined($("#enddate_search").val());
		    data.state = $("#state_search").val();
    		data.sign=GetSign(data.act);
			
			mui.getJSON(index_domain, data, function(json) {
				if(json.data.list.length>0)
				{
					if(pageindex==1)
					{
						$("#contentlist1").html(Employ_Data(json.data.list));
					}else{
						$("#contentlist1").append(Employ_Data(json.data.list));
					}
					setTimeout(function(){
						Init_Employ();
						myScroll1.refresh();
					},500); //需要延迟500毫秒加载，否则当数量少时不能下拉
					if(json.data.list.length!=data.pagesize)
					{
						$("#loading1").html("");
					}else{
						$("#loading1").html('<img src="img/loading.gif"/>');
					}
				}else
				{
					
					if(pageindex==1)
					{
						$("#contentlist1").html("");
						$("#loading1").html("主人，没有找到您需要的数据"); 
					}
					else
					{
						$("#loading1").html("没有更多了");
					}
				}
				
         		pageindex = parseInt($("#divmsg1").attr("pageindex"))+1;
         		$("#divmsg1").attr("pageindex",pageindex);
			});
};
function Init_Employ()
{
	mui("#contentlist1").off("tap",".matelist");
	mui("#contentlist1").on("tap",".matelist",function(){
		obj=$(this);
		OpenWindow(2,"修改应聘","保存",function(){
			Save_Employ();
		});
		$("#contentlist2").html(EmployAdd_Code(obj.attr("id")));
		Init_EmployAdd();
		Init_Role(obj.attr("roleid"));
	});
	
};

function EmployAdd_Code(id){
	
	var buffer = new StringBuffer();
	buffer.append('<div id="employid" class="crmsheet border-bottom" val="'+id+'"><div class="ctitle"><div class="cname">应聘人</div><div class="require">*</div></div><div class="ctext"><input id="txt_realname" type="text" placeholder="填写应聘人姓名" value=""/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">应聘职位</div><div class="require">*</div></div><div class="ctext"><select id="txt_roleid"></select></div><div class="carrow"><img src="img/arrow.png"/></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">性别</div><div class="require">*</div></div><div class="ctext"><div class="sex"><input id="boy" name="sex" type="radio" style="width:16px;" checked="checked" value="男"/><label for="boy">男</label></div><div class="sex"><input id="girls" name="sex" type="radio" style="width:16px;" value="女"/><label for="girls">女</label></div></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">手机</div><div class="require">*</div></div><div class="ctext"><input id="txt_mobile" type="tel" maxlength="11" placeholder="填写手机号码" value="" onfocus="ScrollTop()"/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">QQ</div></div><div class="ctext"><input id="txt_qq" type="tel" placeholder="填写QQ" value="" onfocus="ScrollTop()"/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">毕业院校</div></div><div class="ctext"><input id="txt_school" type="text" placeholder="填写毕业院校" value="" onfocus="ScrollTop()"/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom date"><div class="ctitle"><div class="cname">毕业时间</div></div><div class="ctext"><input id="txt_schooldate" type="text" placeholder="选择毕业时间" value="" readonly="readonly"/></div><div class="carrow"><img src="img/arrow.png"/></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">教育类型</div></div><div class="ctext"><input id="txt_schooltype" type="text" placeholder="填写教育类型" value="" onfocus="ScrollTop()"/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">专业</div></div><div class="ctext"><input id="txt_profession" type="text" placeholder="填写专业" value="" onfocus="ScrollTop()"/></div><div class="carrow"></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">面试状态</div></div><div class="ctext"><select id="txt_state"><option value="1">初试</option><option value="2">复试</option><option value="3">通过</option><option value="4">淘汰</option></select></div><div class="carrow"><img src="img/arrow.png"/></div></div>');
	buffer.append('<div class="crmsheet border-bottom"><div class="ctitle"><div class="cname">面试时间</div></div><div class="ctext"><input id="txt_interviewdate" type="text" placeholder="选择面试时间" value="" readonly="readonly"/></div><div class="carrow"><img src="img/arrow.png"/></div></div>');
	buffer.append('<div id="txt_interviewid" class="crmsheet border-bottom users" show="1" touserid="'+User.ID+'" todepartid="" tocomid=""><div class="ctitle"><div class="cname">面试人</div></div><div class="ctext"><input type="text" placeholder="选择面试人" value="'+User.RealName+'" readonly="readonly"/></div><div class="carrow"><img src="img/arrow.png"/></div></div>');
	buffer.append('<div class="crmsheet border-bottom" style="height:120px;"><div class="ctitle"><div class="cname">面试内容</div></div><textarea id="txt_context" placeholder="填写面试内容" onfocus="ScrollTop()"></textarea></div>');
	if(id!=0){
	buffer.append('<div id="deletesheet" class="deletesheet" style="margin-top:50px;"><div class="name" style="width:100%; text-align:center;">删除该应聘</div></div>');
	}
	return buffer.toString();
};
function Init_Role(roleid){
	var data = {};
		data.act = "DepartAndRole_Data";
		
		data.id=userid;
		data.source=source;
		data.userid=userid;
		data.comid=comid;
		data.sign=GetSign(data.act);
		mui.getJSON(admin_domain, data, function (json) {
		    if (json.state) {
		    	var rolelist=json.data.rolelist;
		    	var str2='';
		    	var isselect2='';
		    	$.each(rolelist,function(i,info){
		    		if (info.ID == roleid)
                    {
                        isselect2 = "selected='selected'";
                    }
                    else {
                        isselect2 = "";
                    } 
		    		str2+='<option value="'+info.ID+'" '+isselect2+'>'+info.Name+'</option>';
		    	});
		    	$("#txt_roleid").html(str2);
		    }
		});
};
function Init_EmployAdd(){
	if($("#employid").attr("val")!="0")
		{
			var data = {};
			data.act = "One_Employ";
			data.id=$("#employid").attr("val");
			data.source=source;
			data.userid=userid;
			data.comid=comid;
			data.sign=GetSign(data.act);
			mui.getJSON(index_domain, data, function (json) {
		            if (json.state) {
		                info=json.data;
		                $("#txt_realname").val(info.RealName);
				        $("#txt_mobile").val(info.Mobile);
				        $("input[name='sex'][value='"+info.Sex+"']").prop("checked", true);
				        $("#txt_qq").val(info.QQ);
				        $("#txt_school").val(info.School);
				        $("#txt_schooldate").val(info.SchoolDate.ToDate());
				        $("#txt_schooltype").val(info.SchoolType);
				        $("#txt_profession").val(info.Profession);
				        $("#txt_state").val(info.State);
				        $("#txt_interviewdate").val(info.InterviewDate);
				        $("#txt_interviewid").attr("touserid",info.InterviewID).find("input").val(info.InterviewName);
				        $("#txt_roleid").val(info.RoleID);
				        $("#txt_context").val(info.Context);
		            } else {
						plus.nativeUI.toast(json.msg); 
		            }
		    });
			get("deletesheet").addEventListener("tap",function(){
		        	plus.nativeUI.confirm("确定要删除吗？", function(event){
						if(event.index==1)
						{
							var data = {};
						    data.act = "Delete_Employ";
						    data.ids = $("#employid").attr("val");
						    data.userid=userid;
							data.comid=comid;
							data.source=source;
							data.sign=GetSign(data.act);
						    mui.getJSON(index_domain, data, function(json) {
								if(json.state)
								{
									obj.hide(200);
									CloseWindow();
									plus.nativeUI.toast(json.msg);
								}else
								{
									plus.nativeUI.alert(json.msg);
								}
								
						    });	
						}
					},"提示", ["取消","确认"]);
				
			});
		}else
		{
			Init_Role(0);
		}
	
	mui(".divmsg").on("tap",".date",function(){
			obj10=this;
			var t=new Date();
			if($(this).find("input").val()!="")
			{
				var year_month_day=$(this).find("input").val().split("-");
				t.setFullYear(year_month_day[0]);
				t.setMonth(year_month_day[1]-1);
				t.setDate(year_month_day[2]);
			}
			plus.nativeUI.pickDate( function(e){
				var d=e.date;
				$(obj10).find("input").val((d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate()).ToDate());
			},function(e){
				console.log( "未选择日期："+e.message );
			},{date:t});
		});
		mui("#divmsg2").on("tap",".users",function(){
		obj10=$(this);
		OpenWindow(3,"选择面试人","确定",function(){
				var str1="";
				var touserid="";
      			var count=0;
      			mui.each(mui("#userlist input"),function(i,info){
      				if(info.checked)
      				{
      					count++;
      					str1 += info.getAttribute("val")+",";
      					touserid += info.value+",";
      				}
      			});
      			
      			if(str1=="")
      			{
      				obj10.find("input").val("");
      			}else
      			{
      				obj10.find("input").val(str1.substring(0,str1.length-1));
      			}
      			
      			obj10.attr("touserid",touserid);
      			if(obj10.attr("show")=="1")
				{
					if(touserid.TrimEnd(",").split(",").length>1)
					{
						plus.nativeUI.toast("请选择1个面试人");
						return;
					}
				}
      			CloseWindow();
		});
		
		$("#contentlist3").html(CheckMate_Data());
		var data = {};
		data.act = "DepartAndUser_Data";
		data.userid=userid;
		data.comid=comid;
		data.source=source;
		data.sign=GetSign(data.act);
		
		mui.getJSON(admin_domain, data, function(json) {
			Bind_CheckMate(json.data.user,json.data.depart);
			Init_CheckMate();
		});
		if(obj10.attr("show")=="1")
      	{
      		$(".selectbar").hide();
      	}else
      	{
			$(".selectbar").show();  				
      	}
		
	});
	
		var currYear = (new Date()).getFullYear();
			var opt={};
			opt.date = {preset : 'date'};
			opt.datetime = {preset : 'datetime'};
			opt.time = {preset : 'time'};
			opt.default = {
				theme: 'android-ics light', //皮肤样式
		        display: 'bottom', //显示方式 
		        mode: 'scroller', //日期选择模式
				dateFormat: 'yyyy-mm-dd',
				lang: 'zh',
				showNow: true,
				nowText: "今天",
				rows: 3,
		        startYear: currYear - 10, //开始年份
		        endYear: currYear + 10 //结束年份
			};
		  	var optDateTime = $.extend(opt['datetime'], opt['default']);
		    $("#txt_interviewdate").mobiscroll(optDateTime).datetime(optDateTime);
		    var today = new Date();
		    $("#txt_interviewdate").scroller('setDate', today, true);
};


function Save_Employ() {
        var data = {};
        var txt_realname = $("#txt_realname");
        var txt_mobile = $("#txt_mobile");
        data.id = $("#employid").attr("val");
        if(txt_realname.val().Trim()=="")
        {
        	plus.nativeUI.toast("请输入应聘人姓名");
        	return false;
        }
        if(txt_mobile.val().Trim()=="")
        {
        	plus.nativeUI.toast("请输入手机号码");
        	return false;
        }
		data.act = "Save_Employ";
		data.realname=txt_realname.val();
		data.mobile=txt_mobile.val();
		data.sex = $("input[name='sex']:checked").val();
		data.mobile = $("#txt_mobile").val();
		data.qq = $("#txt_qq").val();
        data.school = $("#txt_school").val();
        data.schooldate = $("#txt_schooldate").val();
        data.schooltype = $("#txt_schooltype").val();
        data.profession = $("#txt_profession").val();
        data.state=$("#txt_state").val();
        data.interviewdate=$("#txt_interviewdate").val();
        data.interviewid=$("#txt_interviewid").attr("touserid").TrimEnd(",");
        data.roleid=$("#txt_roleid").val();
        data.context=$("#txt_context").val();
        data.userid=userid;
		data.comid=comid;
        data.source = source;
        data.version = version;
        data.sign=GetSign(data.act);
        plus.nativeUI.showWaiting( "正在保存..." );
	    CloseWaiting(10000);
        mui.getJSON(index_domain, data, function (json) {
        	plus.nativeUI.closeWaiting();
        	plus.nativeUI.toast(json.msg); 
            if (json.state) {
                CloseWindow(); 
                if(data.id==0)
                {
                	Employ_Search();
                }else
                {
					obj.find(".realname").html(data.realname);
					obj.find(".sex").html(data.sex);
					obj.find(".state").html(Get_EmployState(data.state));
					obj.attr("roleid",data.roleid);
					obj.find(".interviewdate").html("招聘时间："+data.interviewdate.ToDate());
                }
            }
        });
};

function Get_EmployState(state)
{
	if(state==1){return "初试";}
	else if(state==2){return "复试";}
	else if(state==3){return "通过";}
	else if(state==4){return "淘汰";}
};
